#include <iostream>
#include "GBF2.h"
#include <time.h>
#include <string>
using namespace std;
void to_list( int &numEdge, int &numVeretx);
void to_matrix( int &numEdge, int &numVertex);
int main(){
  int numEdge,numVertex,type = 0;
  
  cout << "选择将要初始化图的存储方式.List输入1，Matrix输入2，由系统决定输入0" << endl;
  cin >> type;
  cout << "输入图中顶点的个数和边的个数"<<endl;
  cin >>numVertex>>numEdge;
  
  /**
   *初始化数组
   */
  if( type == 0 )
    {
      if( numEdge > numVertex*numVertex / 2)
	type = 2;
      else
	type = 1;
    }

    if( type == 1 )
    {
      to_list( numEdge, numVertex );
     } 
   else
    {
      to_matrix( numEdge, numVertex );
   }
    
   
  
  return 0;
}

void to_list( int &numEdge, int &numVertex ){
  int i=0;
  int data_a,data_b;
  int weight = 0;
  string name_a,name_b;

  
  graph_list<int> test;
  
  /**
   *初始化图
   */

    
  for( i=0; i<numVertex; i++)
    {
      cin >> name_a;
      cin >> data_a;
      test.insertVertex( data_a, name_a );
    }
   
   for( i=0; i<numEdge; i++ )
    {
     cin >> name_a >> name_b >> weight;
      test.setEdge( name_a, name_b, weight);
    }
   
  
  /**
   *测试功能
   */
  
 
  test.listVertex();
  cout << "num of vertex:"<<test.num_vertexs()<<endl;
  test.listEdge();
  cout << "\n num of edges:"<<test.num_edges()<<endl;
  
  
   clock_t start,end;
   cin >> name_a;
    start = clock();
   test.BellmanFord( name_a );
   end = clock();
   cout <<"v="<<test.num_vertexs()<<" e="<<test.num_edges()<< " time : "<< end - start<< endl;
  return;
}

void to_matrix( int &numEdge, int &numVertex ){
    int i=0;
  int data_a,data_b;
  int weight = 0;
  string name_a,name_b;
  
  graph_matrix<int>test;

  /**
   *初始化图
   */
  
  for( i=0; i<numVertex; i++)
    {
      cin >> name_a;
      cin >> data_a;
      test.insertVertex( data_a, name_a );
    }
   
   for( i=0; i<numEdge; i++ )
    {
     cin >> name_a >> name_b >> weight;
      test.setEdge( name_a, name_b, weight);
    }

    test.listVertex();
  cout << "num of vertex:"<<test.num_vertexs()<<endl;
  test.listEdge();
  cout << "\n num of edges:"<<test.num_edges()<<endl;
 
  /**
   *测试功能
   */
  
 
   clock_t start,end;
   cin >> name_a;
   start = clock();
   test.BellmanFord( name_a );
   end = clock();
   cout <<"v="<<test.num_vertexs()<<" e="<<test.num_edges() << " time :" << end-start << endl;
   
   
  return;

}
